package learning.lesson.bean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Tools {
	public static Connection connect() throws Exception {

		Class.forName("org.sqlite.JDBC");
		String url = "jdbc:sqlite:/e:/databases/spmarket";
		Connection conn = DriverManager.getConnection(url);
		return conn;
	}

	public static void close(Connection conn, PreparedStatement pst,
			ResultSet rs) {
		try {
			if (conn != null)
				conn.close();
			if (pst != null)
				conn.close();
			if (rs != null)
				conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void close(Connection conn, PreparedStatement pst) {
		try {
			if (conn != null)
				conn.close();
			if (pst != null)
				conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void close(Connection conn) {
		try {
			if (conn != null)
				conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
